package mamma.dao;

import java.util.List;

import mamma.common.MybatisConfig;
import mamma.vo.MemberVo;
import mamma.vo.PhotoVo;
import mamma.vo.SearchVo;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class MemberDao {
	private SqlSessionFactory factory;
	
	public MemberDao(){
		factory = MybatisConfig.getSqlSessionFactory();
	}
	
	// search and check the email
	public boolean emailCheck(String email){
		boolean result = true;			// true means that our database doesn't have this email.
		
		SqlSession session = factory.openSession();
		String searchedEmail = session.selectOne("member.emailCheck", email);
		session.close();
		
		// if it is searched on our database, return false.
		if(searchedEmail != null) result = false;
		
		return result;
	}
	
	// insert the account
	public void insertAccount(MemberVo vo){
		SqlSession session = factory.openSession();
		session.insert("member.insertAccount", vo);
		session.commit();
		
		session.insert("member.insertOwnFriends", vo);
		session.commit();
		session.close();
	}
	
	// select the account
	public MemberVo selectAccount(MemberVo vo){
		SqlSession session = factory.openSession();
		MemberVo tempVo = session.selectOne("member.selectAccount", vo);
		session.close();
		
		return tempVo;
	}

}

